﻿/**
 * Peter
 * Created by: Peter Development Team
 *    http://peter.codeplex.com/
 * 
 * GNU General Public License version 2 (GPLv2)
 *    http://peter.codeplex.com/license
 *
 *  This code is provided on an AS IS basis, with no WARRANTIES,
 *  CONDITIONS or GUARANTEES of any kind.
 *
 **/

using System.Windows.Input;
using Peter.Common.Interfaces;

namespace Peter.Common
{
   /// <summary>
   /// Requried methods and properties for a document content object.
   /// </summary>
   public abstract class PeterDocument : PeterDockItem, IPeterDocument
   {
      private RelayCommand m_CloseCommand;

      /// <summary>
      /// Gets or Sets the project item.
      /// </summary>
      public PeterProjectItem ProjectItem { get; protected set; }

      /// <summary>
      /// Gets the close command.
      /// </summary>
      public ICommand CloseCommand
      {
         get { return this.m_CloseCommand ?? (this.m_CloseCommand = new RelayCommand (this.OnClose, this.CanClose)); }
      }

      /// <summary>
      /// Sets the project item for this document.
      /// </summary>
      /// <param name="projectItem">ProjectItem</param>
      public virtual void SetProjectItem (PeterProjectItem projectItem)
      {
         this.ProjectItem = projectItem;
      }

      /// <summary>
      /// Checks to see if the item can close.
      /// </summary>
      /// <param name="obj">Command parameter.</param>
      /// <returns>True if able to close, otherwise false. Default is true.</returns>
      protected virtual bool CanClose (object obj)
      {
         return true;
      }

      /// <summary>
      /// Closes the current item.
      /// </summary>
      /// <param name="obj">Command parameter.</param>
      protected virtual void OnClose (object obj)
      {
         this.Peter.CloseDocument (this);
      }
   }
}
